package Threads;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.ArrayList;

import Debug.Debug;
import Enums.Type_rsp;
import Structs.Msg_rsp;

public class C_TCP_in implements Runnable {

	private ObjectInputStream in;
	private ArrayList<Msg_rsp> failover;
	
	public C_TCP_in(ObjectInputStream in, ArrayList<Msg_rsp> failover) {
		this.failover=failover;
		this.in = in;
	}
	
	@Override
	public void run() {
		// TODO Auto-generated method stub
		try {
			Msg_rsp input=null;
			while(true){
					if(new Debug().isDebug())
						System.out.println("waiting for requests");
					input = (Msg_rsp) in.readObject();
					if(failover.contains(input))
						failover.remove(input);
					else
						System.out.println(input.getName());
			}
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			if(new Debug().isDebug())
				System.out.println("IO Error in tcp");
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			if(new Debug().isDebug())
				System.out.println("Class not found error");
		}
	}
	
}
